package com.sunfeng.chap2;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description: 正常传输文件
 *  a.txt 文件的初始内容为 abcdefg
 *  b.txt 文件的初始内容为 123456789
 *   结果为:123cde789
 * @Date : 2021/10/9  14:07
 */
public class Test11_2 {
    public static void main(String[] args) throws IOException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("d:\\nio\\a.txt", "rw");
        RandomAccessFile randomAccessFile2 = new RandomAccessFile("d:\\nio\\b.txt", "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();
        FileChannel file2Channel = randomAccessFile2.getChannel();

        file2Channel.position(3);
        fileChannel.transferTo(2,3,file2Channel);
        fileChannel.close();
        file2Channel.close();
        randomAccessFile.close();
        randomAccessFile2.close();
    }
}
